import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:jump_scape/js_ui/js_widget/js_image_view.dart';
import 'package:jump_scape/js_ui/js_widget/js_style.dart';
import 'package:url_launcher/url_launcher.dart';

import '../../js_config.dart';
import '../../js_data/js_event.dart';

jsShowLoginAgreementDialog(
  BuildContext context,
  Function(bool isAgree) onTap,
) {
  showDialog(
    context: context,
    barrierDismissible: false,
    useSafeArea: false,
    barrierColor: Colors.black.withOpacity(0.55),
    builder: ((context) {
      return Column(
        mainAxisAlignment: MainAxisAlignment.center,
        children: [
          Dialog(
            alignment: Alignment.center,
            backgroundColor: Colors.transparent,
            insetPadding: EdgeInsets.zero,
            child: Container(
              width: 315.r,
              padding: EdgeInsets.symmetric(horizontal: 28.r),
              alignment: Alignment.topCenter,
              decoration: jsShapeRound(radius: 18.r, color: Colors.white, borderColor: Colors.black, borderWidth: 1.r),
              child: Column(
                children: [
                  Container(
                    margin: EdgeInsets.only(top: 20.r),
                    decoration: jsShapeRound(radius: 12.r, borderColor: Colors.black, borderWidth: 1.r),
                    child: Container(
                      width: 71.r,
                      height: 71.r,
                      clipBehavior: Clip.antiAlias,
                      decoration: jsShapeRound(radius: 12.r),
                      child: jsImage('assets/image/ic_logo.png'),
                    ),
                  ),
                  SizedBox(height: 15.r),
                  Text(JsApp.appName, style: jsTextStyle(font: JsTextFont.DIN_Alternate, fontColor: Colors.black, fontSize: 20.r)),
                  SizedBox(height: 15.r),
                  Text.rich(
                    textAlign: TextAlign.center,
                    TextSpan(
                      text: 'By using our App you agree with our ',
                      style: jsTextStyle(font: JsTextFont.October_Devanagari_Regular, fontSize: 14.r, fontColor: Color(0xFF050A32), height: 21.0 / 14),
                      children: [
                        TextSpan(
                          text: 'Term of Use',
                          style: jsTextStyle(font: JsTextFont.October_Devanagari_Regular, fontColor: Color(0xFFF46092)),
                          recognizer: TapGestureRecognizer()
                            ..onTap = () {
                              JsEventManager.statPage(page: JsEventName.jsNameTerms);

                              launchUrl(Uri.parse(JsApp.jsTOS));
                            },
                        ),
                        TextSpan(text: ' and '),
                        TextSpan(
                          text: 'Privacy Policy.',
                          style: jsTextStyle(font: JsTextFont.October_Devanagari_Regular, fontColor: Color(0xFFF46092)),
                          recognizer: TapGestureRecognizer()
                            ..onTap = () {
                              JsEventManager.statPage(page: JsEventName.jsNamePrivacy);

                              launchUrl(Uri.parse(JsApp.jsPP));
                            },
                        ),
                      ],
                    ),
                  ),
                  InkWell(
                    child: Container(
                      width: 180.r,
                      height: 44.r,
                      margin: EdgeInsets.only(top: 24.r),
                      alignment: Alignment.center,
                      decoration: jsShapeRound(radius: 22.r, color: Color(0xFFFF84C7)),
                      child: Text('Agree and Continue', style: jsTextStyle(font: JsTextFont.October_Devanagari_Medium, fontSize: 14.r, fontColor: Colors.white)),
                    ),
                    onTap: () {
                      if (Navigator.canPop(context)) {
                        Navigator.pop(context);
                      }
                      onTap(true);
                    },
                  ),
                  InkWell(
                    child: Container(
                      width: 180.r,
                      height: 44.r,
                      margin: EdgeInsets.only(top: 20.r, bottom: 24.r),
                      alignment: Alignment.center,
                      decoration: jsShapeRound(radius: 22.r, borderWidth: 1.r, borderColor: Color(0xFF050A32)),
                      child: Text('Cancel', style: jsTextStyle(font: JsTextFont.October_Devanagari_Regular, fontSize: 14.r, fontColor: Color(0xFF050A32))),
                    ),
                    onTap: () {
                      if (Navigator.canPop(context)) {
                        Navigator.pop(context);
                      }
                      onTap(false);
                    },
                  )
                ],
              ),
            ),
          )
        ],
      );
    }),
  );
}
